<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Plans and Services</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
<link rel="home" href="index.html" title="SPADE User's Manual">
<link rel="up" href="spade.bdi.html" title="Chapter 7. BDI Architecture for SPADE Agents">
<link rel="prev" href="spade.bdi.kb.html" title="The Knowledge Base">
<link rel="next" href="spade.bdi.goals.html" title="Goals">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Plans and Services</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="spade.bdi.kb.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. BDI Architecture for SPADE Agents</th>
<td width="20%" align="right"> <a accesskey="n" href="spade.bdi.goals.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="spade.bdi.plans"></a>Plans and Services</h2></div></div></div>
<p>
            Services in SPADE are offered by agents registered in the system. These services, once are registered in the Directory Facilitator (DF) can be invoked using the RPC facilities of SPADE.
          </p>
<pre class="screen">
        #This is the method executed when the service is invoked
        def s1_method(Value):
            return {"Myoutput1":1} #the return value is a dict containing Facts in the form name:value

        #Create the service profile
        s = DF.Service(name="s1", owner=agent.getAID(), inputs=["Value"],outputs=["O1"],P=["Var(Value,0,Int)"],Q=["Var(O1,1,Int)"])

        #Finally register the service
        agent.registerService(s, s1_method)
        </pre>
<p>A Plan is a sequence of services where each postcondition matches the precondition of the next service. The plan has also a precondition (P) and postcondition (Q) and a set of inputs and outputs:</p>
<pre class="screen">

        agent.addPlan(inputs=["Value"],outputs=["O2"],P=["Var(Value,0,Int)"],Q=["Var(O2,2,Int)"], services=["s1","s2"])
        </pre>
<p>These are pre-compiled plans that the agent may have to improve the plan search. However, SPADE agents have the ability of composing on-line plans, with no need of creating pre-compiled plans.</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="spade.bdi.kb.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="spade.bdi.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="spade.bdi.goals.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">The Knowledge Base </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Goals</td>
</tr>
</table>
</div>
</body>
</html>
